package com.skinchange.attr;

import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.skinchange.skin.ResourcesManager;
import com.skinchange.skin.SkinManager;

/**
 * Description:
 * Author: Author
 * Date: 2017-08-08
 * Time: 16:40
 */


public enum  SkinAttrType {

    BACKGROUND("background"){
        public void apply(View view, String resName) {
            Drawable drawable = getResourcesManager().getDrawableByResName(resName);
            if (drawable != null)
            view.setBackgroundDrawable(drawable);
        }
    },SRC("src") {
        @Override
        public void apply(View view, String resName) {
            Drawable drawable = getResourcesManager().getDrawableByResName(resName);
            if (view instanceof ImageView){
                ImageView imageView = (ImageView) view;
                if (drawable != null)
                    imageView.setImageDrawable(drawable);
            }

        }
    },TEXT_COLOR("textColor") {
        @Override
        public void apply(View view, String resName) {
            ColorStateList colorStateList = getResourcesManager().getColorByResName(resName);
            if (view instanceof TextView){
                TextView textView = (TextView) view;
                if (colorStateList != null)
                    textView.setTextColor(colorStateList);
            }
        }
    };

    public String resType;

    public String getResType() {
        return resType;
    }



    SkinAttrType(String type) {

        resType = type;
    }

    public abstract void apply(View view,String resName);


    public ResourcesManager getResourcesManager(){
        return SkinManager.getInstance().getResourcesManager();
    }
}
